package ssen.mvc.base {
import flash.events.IEventDispatcher;

import ssen.mvc.core.ICommandMap;
import ssen.mvc.core.IContext;
import ssen.mvc.core.IContextDispatcher;
import ssen.mvc.core.IContextView;
import ssen.mvc.core.IContextViewInjector;
import ssen.mvc.core.IInjector;
import ssen.mvc.core.IViewCatcher;
import ssen.mvc.core.IViewCreator;
import ssen.mvc.core.IViewInjector;

public class Context implements IContext {
	private var _contextView:IContextView;
	private var _parentContext:IContext;

	public function Context(contextView:IContextView, parentContext:IContext=null) {
		_parentContext=parentContext;
		_contextView=contextView;

		initialize();
	}

	protected function initialize():void {
		injector.mapValue(IInjector, injector);
		injector.mapValue(IEventDispatcher, dispatcher.eventDispatcher);
		injector.mapValue(IContextDispatcher, dispatcher);
		injector.mapValue(IViewCreator, viewCreator);
		injector.mapValue(IContextView, contextView);
		injector.mapValue(ICommandMap, commandMap);

		mapDependency();

		viewCatcher.start(contextView);
	}

	protected function mapDependency():void {
		trace("Context.mapDependency");
	}

	protected function startup():void {
		trace("Context.startup");
	}

	protected function shutdown():void {
		trace("Context.shutdown");
	}

	protected function dispose():void {
		viewCatcher.stop();

		dispatcher.dispose();
		injector.dispose();
		viewCatcher.dispose();
		viewCreator.dispose();
		viewInjector.dispose();
		contextViewInjector.dispose();
		commandMap.dispose();

		_contextView=null;
		_parentContext=null;
	}

	final protected function get contextView():IContextView {
		return _contextView;
	}

	final protected function get parentContext():IContext {
		return _parentContext;
	}

	//=========================================================
	// 
	//=========================================================
	public function get dispatcher():IContextDispatcher {
		throw new Error("not implemented");
	}

	public function get injector():IInjector {
		throw new Error("not implemented");
	}

	protected function get viewCatcher():IViewCatcher {
		throw new Error("not implemented");
	}

	protected function get viewCreator():IViewCreator {
		throw new Error("not implemented");
	}

	protected function get viewInjector():IViewInjector {
		throw new Error("not implemented");
	}

	protected function get contextViewInjector():IContextViewInjector {
		throw new Error("not implemented");
	}

	public function get commandMap():ICommandMap {
		throw new Error("not implemented");
	}

}
}
